var express = require('express');
var router = express.Router();
var addressesService = require('../service/addressesService.js')
/* GET users listing. */
router.get('/',async function (req, res, next) {
  let data = await addressesService.findAll();
  res.send(data);
});

// 查询通过userId
router.get('/byuser/:id',async function (req, res, next) {
  let id = req.params.id
  let data = await addressesService.findByuser({ userId: id });
  res.send(data);
});

// 增加
router.post('/', async function (req, res, next) {
  let data = await addressesService.insert(req.body)
  res.send(data);
});

// 删除
router.delete('/:id', async function (req, res, next) {
  let id = req.params.id
  let data = await addressesService.delete(id)
  res.send(data);
});

// 修改
router.put('/:id', async function (req, res, next) {
  let id = req.params.id
  console.log(req.body);
  let data = await addressesService.update(id, req.body)
  res.send(data);
});

module.exports = router;
